package com.hmall.order.interceptor;


import com.hmall.order.context.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
@Slf4j
public class AuthorizationInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String requestHeader = request.getHeader("authorization");

        if (StringUtils.isNoneEmpty(requestHeader)){
            BaseContext.setCurrentId(Long.valueOf(requestHeader));
            log.info("-----userId:{}-----",requestHeader);
        }

        return true;

    }
}
